package com.ycxh.util;

/**
 * 文件工具类
 */
public class FileUtil {

    private static final long SIZE_K = 1024L;

    private static final long SIZE_M = SIZE_K * 1024L;

    private static final long SIZE_G = SIZE_M * 1024L;

    /**
     * 获取文件后缀，即文件类型
     */
    public static String getFileType(String fileName) {
        String rs = null;
        if (fileName != null) {
            int index = fileName.lastIndexOf(".");
            rs = fileName.substring(index + 1);
        }
        return rs;
    }

    /**
     * 拼接路径
     */
    public static String getFilePath(String dir, String path) {
        String rs = dir;
        if (dir == null || dir.isEmpty()) {
            return path;
        }
        if (dir.endsWith("/") || path.startsWith("/")) {
            rs = dir + path;
        } else {
            rs = dir + "/" + path;
        }
        return rs;
    }

    /**
     * 获取文件名
     */
    public static String getFileName(String filePath) {
        String rs = filePath;
        int index = filePath.lastIndexOf("/");
        if (index == -1) {
            index = filePath.lastIndexOf("\\");
        }
        if (index != -1) {
            rs = filePath.substring(index + 1);
        }
        return rs;
    }

}

